package com.ccs.testcase;

import java.util.concurrent.TimeUnit;

import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.openqa.selenium.WebDriver;

import com.ccs.functions.Login;
import com.ccs.functions.Logout;
import com.ccs.functions.Webdriver;
import com.ccs.loas.CreateLOA;
import com.ccs.loas.Hcs_Methods;
import com.ccs.loas.Miscellaneous;
import com.ccs.loas.SearchFunctionLoa;
import com.ccs.testdatas.Billing;
import com.ccs.testdatas.Nursing;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class Loa_NotAllCovered {
	
	public static String appCode;
	private static String loa_number;
	private static WebDriver driver;
	private static String pin;
	
	@BeforeClass
	public static void startBrowser()throws Exception{
		Webdriver d = new Webdriver();
		driver = d.startUp();
	}
	
	@Test
	public void a_login() throws Exception{
		System.out.println("Start Test: LOGIN");
		Login in = new Login();
		in.app(driver);
		System.out.println("End Test: LOGIN\n");
	}
	@Test
	public void b_create_loa() throws Exception{
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		System.out.println("Start Test: Create Loa");
		CreateLOA loa = new CreateLOA();
		String returnedString = loa.create(driver, "notcovered");
		String[] arrString = returnedString.split(",");
		loa_number = arrString[1];
		pin = arrString[0];
		System.out.println("Loa Number: "+loa_number);
		System.out.println("End Test: Create Loa\n");
	}
	@Test
	public void c_search_draft_loa() throws Exception{
		System.out.println("Start Test: SEARCH DRAFT LOA");
		SearchFunctionLoa search_loa = new SearchFunctionLoa();
		search_loa.search(driver, "number", loa_number);
		System.out.println("End Test: SEARCH DRAFT LOA\n");
	}
	@Test
	public void d_select_draft_loa() throws Exception{
		System.out.println("Start Test: SELECT DRAFT LOA");
		SearchFunctionLoa search_loa = new SearchFunctionLoa();
		String status = search_loa.select(driver, "edit");
		if(status.equals("New")){
			System.out.println("Status of Draft LOA: CORRECT");
		}else{
			System.out.println("Status of Draft LOA: INCORRECT");
		}
		System.out.println("End Test: SELECT DRAFT LOA\n");
	}
	@Test
	public void e_generate_final_loa() throws Exception{
		System.out.println("Start Test: GENERATE FINAL LOA");
		Miscellaneous m = new Miscellaneous();
		m.loa_buttons(driver, "final", "");
		System.out.println("LOA is Finalized for Review");
		System.out.println("End Test: GENERATE FINAL LOA\n");
	}
	@Test
	public void f_search_final_loa() throws Exception{
		System.out.println("Start Test: SEARCH PENDING LOA");
		SearchFunctionLoa search_loa = new SearchFunctionLoa();
		search_loa.search(driver, "number", loa_number);
		System.out.println("End Test: SEARCH PENDING LOA\n");
	}
	@Test
	public void g_select_final_loa() throws Exception{
		System.out.println("Start Test: SELECT FINAL LOA");
		SearchFunctionLoa search_loa = new SearchFunctionLoa();
		String status = search_loa.select(driver, "review");
		if(status.equals("Pending")){
			System.out.println("Status of Final LOA: CORRECT");
		}else{
			System.out.println("Status of Final LOA: INCORRECT");
		}
		System.out.println("End Test: SELECT FINAL LOA\n");
	}
	@Test
	public void h_approve_loa() throws Exception{
		System.out.println("Start Test: APPROVE LOA");
		Miscellaneous m = new Miscellaneous();
		m.loa_buttons(driver, "approve", "");
		System.out.println("End Test: APPROVE LOA\n");
	}
	@Test
	public void i_search_approved_loa() throws Exception{
		System.out.println("Start Test: SEARCH APPROVED LOA");
		SearchFunctionLoa search_loa = new SearchFunctionLoa();
		search_loa.search(driver, "number", loa_number);
		System.out.println("End Test: SEARCH APPROVED LOA\n");
	}
	@Test
	public void j_select_approved_loa() throws Exception{
		System.out.println("Start Test: SELECT APPROVED LOA");
		SearchFunctionLoa search_loa = new SearchFunctionLoa();
		String status = search_loa.select(driver, "slmc");
		if(status.equals("Approved")){
			System.out.println("Status of Approved LOA: CORRECT");
		}else{
			System.out.println("Status of Approved LOA: INCORRECT");
		}
		System.out.println("End Test: SELECT APPROVED LOA\n");
	}
	@Test
	public void k_submit_slmc_loa() throws Exception{
		System.out.println("Start Test: SUBMIT TO SLMC LOA");
		Miscellaneous m = new Miscellaneous();
		m.loa_buttons(driver, "submit", "0");
		System.out.println("End Test: SUBMIT TO SLMC LOA\n");
	}
	@Test
	public void l_search_submitted_loa() throws Exception{
		System.out.println("Start Test: SEARCH SUBMITTED TO SLMC LOA");
		SearchFunctionLoa search_loa = new SearchFunctionLoa();
		search_loa.search(driver, "number", loa_number);
		System.out.println("End Test: SEARCH SUBMITTED TO SLMC LOA\n");
	}
	@Test
	public void m_logout_loa() throws Exception{
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		System.out.println("Start Test: LOGOUT");
		Logout out = new Logout();
		out.app(driver);
		System.out.println("End Test: LOGOUT\n");
	}	
	@Test
	public void n_clinic_discharge() throws Exception{
		System.out.println("Start Test: CLINIC DISCHARGE");
		Login in = new Login();
		Hcs_Methods hcs = new Hcs_Methods();
		Nursing nurse = new Nursing();
		Logout out = new Logout();
		in.hcs(driver, "nursing");
		hcs.go_to_gu_landing_page(driver);
		nurse.discharge(driver, pin, "inpatient");
		hcs.go_to_general_units(driver);
		hcs.search_pin(driver, pin);
		hcs.add_pf_doctor(driver);
		hcs.add_second_doctor(driver);
		hcs.clinic_discharge(driver);
		out.hcs(driver);
		System.out.println("End Test: CLINIC DISCHARGE\n");
	}
	@Test
	public void o_login_ccs_webapp() throws Exception{
		System.out.println("Start Test: LOGIN");
		Login in = new Login();
		in.app(driver);
		System.out.println("End Test: LOGIN\n");
	}
	@Test
	public void p_search_forUpdate_loa() throws Exception{
		System.out.println("Start Test: SEARCH LOA");
		SearchFunctionLoa search_loa = new SearchFunctionLoa();
		search_loa.search(driver, "number", loa_number);
		System.out.println("End Test: SEARCH LOA\n");
	}
	@Test
	public void q_Update_loa() throws Exception{
		System.out.println("Start Test: UPDATE LOA");
		SearchFunctionLoa search_loa = new SearchFunctionLoa();
		search_loa.select(driver, "edit");
		Miscellaneous m = new Miscellaneous();
		m.update_doctors(driver);
		search_loa.search(driver, "number", loa_number);
		search_loa.select(driver, "review");
		m.loa_buttons(driver, "approve", "");
		search_loa.search(driver, "number", loa_number);
		search_loa.select(driver, "slmc");
		m.loa_buttons(driver, "submit", appCode);
		System.out.println("End Test: UPDATE LOA\n");
	}
	@Test
	public void r_bill_discharge() throws Exception{
		System.out.println("Start Test: BILL DISCHARGE");
		Login in = new Login();
		Hcs_Methods hcs = new Hcs_Methods();
		Logout out = new Logout();
		Billing bill = new Billing();
		in.hcs(driver, "billing");
		//philhealth goes here
		//hcs.goto_philhealth_form(driver, pin);
		//hcs.philhealth_form(driver);
		bill.goto_discharge_home(driver, pin);
		bill.select_discharge(driver, "regular");
		hcs.billing_guarantor_checking(driver, loa_number, "notcovered");
		hcs.cash_payment(driver);
		out.hcs(driver);
		System.out.println("End Test: BILL DISCHARGE\n");
	}
	
	
	
}
